CFLAGS := $(CFLAGS)  -pedantic
CXX= g++

#define OUTPUT_STATISTICS 
#define USE_THREADS 
#define USE_MATLAB

#ifdef USE_THREADS
BOOST_ROOT := /home/nouri/codes/libs/boost_1_39_0/
CFLAGS := $(CFLAGS) -I$(BOOST_ROOT)
LDFLAGS := $(LDFLAGS) -L$(BOOST_ROOT)/lib/ -lboost_date_time-gcc41-mt-1_39 -lboost_thread-gcc41-mt-1_39
#endif

#ifdef USE_MATLAB 
MATLAB_ROOT := /usr/local/matlab
CFLAGS := $(CFLAGS) -I$(MATLAB_ROOT)/extern/include
LDFLAGS := $(LDFLAGS) -L$(MATLAB_ROOT)/bin/glnxa64 -lmx -lmex -lmat -leng
#endif

BINARY = mre_agent


AGENTSRC = AgentProxy.cpp MREAgent.cpp GridSolver.cpp TFGenerator.cpp FittedVISolver.cpp Grid.cpp KDTree.cpp KDTreeLearner.cpp KNode.cpp LocalRegression.cpp MDPSolver.cpp OriginalRewardGenerator.cpp OriginalTFGenerator.cpp ParamReader.cpp RFGeneralizer.cpp Util.cpp GenericMessage.cpp ValueFunctionRequestMessage.cpp ValueFunctionResponseMessage.cpp MatlabDrawer.cpp 
AGENTOBJ = $(addprefix Build/, $(addsuffix .o, $(basename $(AGENTSRC))))
ENV = ../../env/MountainCar/MountainCar.cpp
ENVOBJ = $(addsuffix .o, $(basename $(ENV))) 

all: $(AGENTOBJ) $(ENVOBJ) 
	${CXX}  $(LDFLAGS) $^ -lm -lrlutils -lrlagent -lrlgluenetdev -o $(BINARY)

local: $(AGENTOBJ) $(ENVOBJ) Build/main.o 
	${CXX}  $(LDFLAGS) $^ -lm -lrlutils -lrlagent  -o $(BINARY)


Build/%.o: %.cpp
	${CXX}  $(CFLAGS) -o $@  -c $<

clean:
	rm -rf $(BINARY) core* Build/*.o

kill: 
	killall -9 $(BINARY)
run:
	./$(BINARY) 127.0.0.1 4096 > result.out & 
	tailf result.out | grep episode 

